package server;

import lombok.Data;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * @Author: zhouzhijun
 * @Date: 2021/4/22 15:14
 */
@Data
public class Service {

    private Engine engine;

    private Connector connector;

    public void init(ThreadPoolExecutor threadPoolExecutor) throws IOException {
        engine.init();
        ServerSocket serverSocket = new ServerSocket(connector.getPort());
        while (true){
            Socket socket = serverSocket.accept();
            RequestProcessor requestProcessor = new RequestProcessor(socket, engine);
            threadPoolExecutor.execute(requestProcessor);
        }
    }

}
